package pojo;

import java.util.Comparator;
import java.util.Objects;

/**
 * 功能描述: 节点信息
 * 2024/05/19
 *
 * @see Comparator
 * ZhangYi
 */
public class TreeNode implements Comparator {
    private int id;
    private String userName;

    public TreeNode left;
    public TreeNode right;

    public TreeNode(int id,
                    String userName) {
        this.id = id;
        this.userName = userName;
    }

    @Override
    public int compare(Object o1,
                       Object o2) {
        TreeNode node1 = (TreeNode) o1;
        TreeNode node2 = (TreeNode) o2;
        if (node1.id == node2.id){
            return node1.userName.compareTo(node2.userName);
        }else {
            return node1.id - node2.id;
        }

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TreeNode treeNode = (TreeNode) o;
        return id == treeNode.id && Objects.equals(userName,
                                                   treeNode.userName) ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id,
                            userName,
                            left,
                            right);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "id=" + id +
                ", userName='" + userName + '\'' +
                ", left=" + left +
                ", right=" + right +
                '}';
    }
}
